<template>
    <div class="header">
        <div class="header_inner">
            <div class="header_left">
                <div class="logo" :style="{backgroundImage:'url('+dsp_logo+')'}" @click.stop="$router.push('/')"></div>

                <div class="index head_left_item"
                     :class="$route.path.split('/')[2].substring(0,3).includes('dsp') ? 'select_style': ''"
                     @click="change_select_index(1,'/dsp/dspJuBen')">短视频
                </div>

                <div class=" head_left_item" style="margin-left: 23px;"
                     :class="$route.path.split('/')[2].substring(0,3).includes('zj') ? 'select_style': ''"
                     @click="change_select_index(1,'/dsp/zj')">短视频征集
                </div>

                <div class="author head_left_item"
                     :class="$route.path.split('/')[2].includes('author') ? 'select_style': ''"
                     @click="change_select_index(2,'/dsp/authorList')">原创作者
                </div>

                <div class="dept head_left_item"
                     :class="$route.path.split('/')[2].includes('yunying') ? 'select_style': ''"
                     @click="change_select_index(3,'/dsp/yunying',1)">运营机构
                </div>

                <div class="video_number head_left_item"
                     :class="$route.path.split('/')[2].includes('videolist') ? 'select_style': ''"
                     @click="change_select_index(4,'/dsp/videolist')">视频号
                </div>

            </div>

            <div class="header_right">


<!--                                <div class="chuang_zuo" @click.stop="$router.push('/dsp/upArticle')">-->
<!--                                    <div class="chuang_zuo_icon el-icon-plus"></div>-->
<!--                                    <div class="chuang_zuo_text">征集</div>-->
<!--                                </div>-->

<!--                                <div class="img_and_name">-->
<!--                                    <div class="img">-->
<!--                                        <el-avatar :size="30" src="https://img1.baidu.com/it/u=1522015854,2481348088&fm=26&fmt=auto" fit="fill">-->
<!--                                            <img src="https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png"/>-->
<!--                                        </el-avatar>-->
<!--                                    </div>-->
<!--                                    <div class="name">-->
<!--                                        倪妮-->
<!--                                    </div>-->
<!--                                </div>-->



                <div class="btnRight">
                    <div class="author" @click="userToAuthor" v-if="!creation&&!(userInfo.status==2)" style="width: 90px;"><span>成为作者</span></div>
                    <router-link :to="{ name: 'creat' }" class="creation" v-if="creation" style="width: 90px;">
                        <i class="el-icon-plus"></i>
                        创作
                    </router-link>
                    <div
                            v-if="!(userInfo.username || userInfo.userName)"
                            class="resgin"

                            style="width: 90px;"
                    >
                        <span @click="login(false)">注册</span> <span class="bor"></span> <span @click="login(true)">登录</span>
                    </div>
                    <div v-else class="logined">

                        <div class="to_zheng_ji" @click.stop="$router.push('/dsp/upArticle')">征集</div>

                        <el-dropdown>
            <span class="el-dropdown-link">

                    <span class="img">
                        <el-avatar :size="30" :src="userAvatar" fit="fill">
                            <img src="https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png"/>
                        </el-avatar>
                    </span>
              {{ userInfo.username || userInfo.userName }}
            </span>
                            <template #dropdown>
                                <el-dropdown-menu>
                                    <el-dropdown-item @click="$router.push('/my')">我的</el-dropdown-item>
                                    <el-dropdown-item @click="$router.push('/creation')">创作管理</el-dropdown-item>
                                    <el-dropdown-item><router-link :to="{ name: 'personalCenter' }">个人中心</router-link></el-dropdown-item>
                                    <el-dropdown-item @click="logout">退出</el-dropdown-item>
                                </el-dropdown-menu>
                            </template>
                        </el-dropdown>
                    </div>
                </div>

            </div>

        </div>
        <Login ref="login" :islogin="islogin"></Login>
        <Author ref="author"></Author>
    </div>
</template>

<script>
    import dsp_logo from '@/assets/img/dsp_page/dsp_logo.png'
    import {reactive} from 'vue'

    import Login from "@/pages/common/login.vue";
    import Author from "@/pages/common/author.vue";
    import { Logout } from "@/api/UserInfo"
    import { getUserInfo, removeUserInfo } from "@/utils/auth";
    import baseConfig from "@/utils/config"

    export default {
        name: "dspHeader",
        components: {
            Login,
            Author,
        },

        watch:{
            userInfo(nv){
                debugger
            }
        },

        computed:{
            userAvatar(){
                return baseConfig.dev+this.$store.state.userInfo.userAvatar
            },
            userInfo(){
                return this.$store.state.userInfo
            }
        },

        watch:{
            $route(to,form) {
                if(to.name=='creation'||to.name=='creat'){
                    this.creation = true
                }else{
                    this.creation = false
                }
            },
            userInfo:{
                handler(nv){
                    debugger
                },
                deep:true
            },
        },

        data() {
            return {
                dsp_logo,
                current_select: 1,
                creation:false,
                islogin:true,
            }
        },




        methods: {
            change_select_index(index,path,query){
                this.current_select=index
                if(query)
                    this.$router.push({path:path,query:{organTypeId:query}})
                else
                    this.$router.push(path)
            },

            to(name){
                if(!this.userInfo.userName){
                    this.login()
                    return false
                }
                if(name=='creation'&&this.userInfo.status!=2){
                    this.userToAuthor()
                    return false
                }
                this.$router.push({name:name})
            },
            login(login_or_register) {
                this.islogin=login_or_register;
                this.$refs.login.dialogVisible = true;
            },
            logout() {
                this.userInfo = {};
                Logout().then((res)=>{})
                removeUserInfo();
                this.$store.commit('setUser',{})
                this.$router.push({ path: "/" });
            },
            userToAuthor() {

                if(getUserInfo() == undefined){
                    this.$message.error('请先登录')
                    return
                }else{
                    this.$refs.author.dialogVisible = true;
                }

            },

        }
    }
</script>

<style scoped lang="scss">
    .header {
        position: sticky;
        top: 0px;
        width: 100%;
        height: 70px;
        background: #FFFFFF;
        z-index: 2000;
    }

    .header_inner {
        width: 1001px;
        height: 100%;
        margin: 0px auto;
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .header_left {
        display: flex;
        align-items: center;
    }

    .index {
        margin-left: 60px;
    }

    .logo {
        width: 146px;
        height: 48px;
        background: 100% 100% no-repeat;
        cursor: pointer;
    }

    .author {
        margin-left: 23px;
    }

    .dept {
        margin-left: 23px;
    }

    .video_number {
        margin-left: 23px;
    }

    .head_left_item {
        box-sizing: border-box;
        border-top: 3px solid #FFFFFF;
        padding-bottom: 3px;
        cursor: pointer;

        height: 50px;
        font-size: 14px;
        line-height: 50px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #999999;

    }

    .select_style {
        border-top: 3px solid #2EB0C6;
        color: #333333;
    }

    .header_right {
        display: flex;
        justify-content: space-between;
        align-items: center;
    }

    .chuang_zuo {
        width: 61px;
        height: 27px;
        border: 1px solid #2EB0C6;
        border-radius: 13px;
        display: flex;
        justify-content: space-between;
        align-items: center;
        cursor: pointer;
    }

    .chuang_zuo_icon {
        font-size: 10px;
        line-height: 27px;
        color: #2EB0C6;
        margin-left: 14px;
    }

    .chuang_zuo_text {
        width: 24px;
        font-size: 12px;
        line-height: 27px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #2EB0C6;
        margin-right: 9px;
    }

    .img_and_name {
        height: 50px;
        margin-left: 18px;
        cursor: pointer;
        display: flex;
        justify-content: space-between;
        align-items: center;

    }

    .img {
        margin-top: 2px;
    }

    .name {
        margin-left: 5px;
        height: 50px;
        font-size: 12px;
        line-height: 50px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #333333;
    }

    .btnRight {
        display: flex;
        font-size: 14px;
        & > div {
            /*width: 188px;*/
            width: 188px;
            height: 28px;
            display: flex;
            align-items: center;
            justify-content: end;
            border-radius: 14px;
            box-sizing: border-box;
            .el-dropdown-link{
                display: flex;
                align-items: center;
                .img{
                    padding-right: 10px;
                }
            }
            span {
                cursor: pointer;
                margin: 0px auto;
            }
            &.author {
                border: 1px solid #2eb0c6;
                color: #2eb0c6;
                margin-right: 20px;
            }
            &.resgin {
                background: #2eb0c6;
                color: #fff;
                span.bor {
                    width: 1px;
                    background: #fff;
                    height: 12px;
                    display: block;
                    margin: 0 4px;
                }
            }
        }


        .creation {
            border: 1px solid #2eb0c6;
            border-radius: 13px;
            width: 61px;
            height: 27px;
            display: flex;
            align-items: center;
            justify-content: center;
            color: #2eb0c6;
            font-size: 12px;
            cursor: pointer;
            i{
                margin-right: 5px;
            }
        }
    }

    .to_zheng_ji{
        width: 61px;
        height: 27px;
        border: 1px solid #2EB0C6;
        border-radius: 13px;
        cursor: pointer;

        font-size: 12px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #2EB0C6;
        text-align: center;
        line-height: 27px;
        margin-right: 10px;
    }

</style>
